//
//  JWTAboutJWT.m
//  JWT
//
//  Created by ndm on 17/2/11.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTAboutJWTView.h"
#import "JWTAboutJWTCell.h"

static NSString *AboutJWT_identifier = @"AboutJWT_identifier";

@interface JWTAboutJWTView ()

@property (nonatomic,strong) NSArray *leftNameArray;

@end

@implementation JWTAboutJWTView
SHARED_INSTANCE_IMPLEMENTATION(JWTAboutJWTView);

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 获取app图标
        NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
        NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
        
        _leftNameArray = @[@"版本号",@"用户协议"];
        
        _jwtLogoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(Cell_Margin, 10*Cell_Margin, 100, 100)];
        _jwtLogoImageView.layer.borderWidth = 0.5;
        _jwtLogoImageView.image = [UIImage imageNamed:icon];
        [self addSubview:_jwtLogoImageView];
        _jwtLogoImageView.center = CGPointMake(UISCREEN_WIDTH*0.5, _jwtLogoImageView.center.y);
        
        _jwtNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(Cell_Margin, _jwtLogoImageView.bottom+Cell_Margin, UISCREEN_WIDTH-2*Cell_Margin, 44)];
        _jwtNameLabel.font = Text_Font16;
        _jwtNameLabel.text = @"金舞团";
        [self addSubview:_jwtNameLabel];
        _jwtNameLabel.center = CGPointMake(_jwtLogoImageView.center.x, _jwtNameLabel.center.y);
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _jwtNameLabel.bottom+4*Cell_Margin, UISCREEN_WIDTH, 44*2)];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.scrollEnabled = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        [self addSubview:_tableView];
        [_tableView registerClass:[JWTAboutJWTCell class] forCellReuseIdentifier:AboutJWT_identifier];
        
        
    }
    return self;
}

#pragma mark - 表格视图数据源代理方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _leftNameArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JWTAboutJWTCell *cell = [tableView dequeueReusableCellWithIdentifier:AboutJWT_identifier forIndexPath:indexPath];
    cell.leftNameLabel.text = [_leftNameArray objectAtIndex:indexPath.row];
    if (indexPath.row == 0) {
        
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        // app版本
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

        cell.rightContentLabel.text = app_Version;
    } else {
        cell.rightContentLabel.text = @"";
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return  cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
